
#-------------------------------------------------
#
# Project created by Vim 2020-01-03 17:28:12
#
#-------------------------------------------------

#===============================================================================
# dir
#===============================================================================
DIR_INC := ./
DIR_SRC := ./
DIR_OBJ := ./obj
DIR_BIN := .

#===============================================================================
# settings
#===============================================================================
define make_dir
	$(foreach str, \
		$(addprefix ${DIR_OBJ}/,${DIR_SRC}), \
		$(shell mkdir -p ${str}))
endef
$(call make_dir)

## get src files from dirs with suffixs: (#dirs, #suffixs)
get_src = $(filter $(addprefix %.,$(2)),$(wildcard $(addsuffix /*,$(1))))

## get suffix files in dir from files: (#dir, #suffix, #files)
get_suf = $(addprefix $(1)/,$(addsuffix .$(2),$(basename $(3))))

## create obj target: (#obj_dir, #src_files, #cxxflags)
define do_create_obj_target
$(1)/$(basename $(2)).o: $(2)
	$(V)$(CC) -c $$< $(3) -o $$@ -MD -MP -MT $$@ -MT $$*.d -MF $$*.d
endef
create_obj_target = $(foreach line,$(2),$(eval $(call do_create_obj_target,$(1),$(line),$(3))))

CC         := g++
TARGET 	   := usestl
ifeq (${CC}, g++)
CC_SUF     := c cc cpp cxx
else
CC_SUF     := c cc
endif
BIN        := ${DIR_BIN}/${TARGET}
SRC        := $(call get_src,${DIR_SRC},${CC_SUF})
OBJ        := $(call get_suf,${DIR_OBJ},o,${SRC})
DEP        := $(call get_suf,${DIR_OBJ},d,${SRC})
LIBS       :=
#-lpthread `pkg-config opencv --libs`
PKGFLAGS   :=
#`pkg-config opencv --cflags`
CXXFLAGS   := -g -Wall
CXXFLAGS   += $(addprefix -I, $(DIR_INC))
CXXFLAGS   += ${PKGFLAGS}
LDFLAGS    := ${LIBS}

#===============================================================================
# target
#===============================================================================
${BIN}: ${OBJ}
	${CC} $^ -o $@ ${CXXFLAGS} ${LDFLAGS}

$(call create_obj_target,${DIR_OBJ},${SRC},${CXXFLAGS})

-include ${DEP}

.phony: clean
clean:
	-rm -r ${DIR_OBJ}
	-rm ${BIN}
